﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;

namespace BLL
{
    public class EnumHelper
    {
        /// <summary>
        /// 账户操作分类
        /// </summary>
        public enum AccountType
        {
            返利,
            退款,
            提现,
            消费
        }
        #region .相关方法 .
        /// <summary>
        /// 根据枚举类型获得该类型下值的集合
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <returns>枚举值的集合</returns>
        public static IList GetEnumItems(Type enumType)
        {
            if (enumType.IsEnum != true)
            {
                // 不是枚举类型 
                throw new InvalidOperationException();
            }

            ArrayList list = new ArrayList();
            foreach (int i in Enum.GetValues(enumType))
            {
                ListItem listitem = new ListItem(Enum.GetName(enumType, i), i.ToString());
                list.Add(listitem);
            }
            return list;
        }
        /// <summary>
        /// 获取枚举类型的值
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="Name">枚举名称</param>
        /// <returns></returns>
        public static object GetEnumValue(Type enumType, string Name)
        {
            if (enumType.IsEnum != true)
            {
                // 不是枚举类型 
                throw new InvalidOperationException();
            }
            int[] Value = (int[])Enum.GetValues(enumType);
            object retrunObj = null;
            for (int i = 0; i < Enum.GetNames(enumType).Length; i++)
            {
                if (Name.Equals(Enum.GetNames(enumType)[i]))
                {
                    retrunObj = Value[i];
                    break;
                }
            }
            return retrunObj;
        }
        /// <summary>
        /// 获取枚举类型的名称
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="Name">枚举值</param>
        /// <returns></returns>
        public static object GetEnumName(Type enumType, int EnumValue)
        {
            if (enumType.IsEnum != true)
            {
                // 不是枚举类型 
                throw new InvalidOperationException();
            }
            object retrunObj = null;

            retrunObj = Enum.GetName(enumType, EnumValue);

            return retrunObj;
        }
        #endregion
    }
}
